package com.le.dub.service.thread;

import cn.hutool.core.util.ObjectUtil;
import com.le.dub.conf.RedisKey;
import com.le.dub.conf.ThreadPoolConfig;
import com.le.dub.service.IAppVoiceService;
import com.le.dub.service.task.ExecuteVoiceTask;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class VoiceThread implements Runnable {
    @Resource
    private RedisTemplate template;
    @Resource
    private ExecuteVoiceTask  executeVoiceTask;

    @Override
    public void run() {
        while (true) {
            Integer executeVoiceNum = (Integer) template.opsForValue().get(RedisKey.executeVoiceNum);
            if (executeVoiceNum >= 5) {
                log.info("当前任务最大执行数已满，排队等待");
                continue;
            }
            if (template.hasKey(RedisKey.voiceList)) {
                //获取队列中语音任务id
                Long recordId = Long.valueOf(template.opsForList().leftPop("voiceList").toString());
                log.info("开始执行任务" + recordId);
                 log.info("Thread" + Thread.currentThread().getName());
                executeVoiceTask.executeVoiceTask(recordId);

            }


        }


    }
}
